﻿using MediatR;
using Traceability.App.API.Application.Command.Slaughter;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.Slaughter
{
    public class GetSlaughterHandler : IRequestHandler<GetSlaughterCommand, APIResult<SlaughterModel>>
    {
        private readonly IBaseRepository<SlaughterModel> salughterRepo;

        public GetSlaughterHandler(IBaseRepository<SlaughterModel> salughterRepo)
        {
            this.salughterRepo = salughterRepo;
        }
        public Task<APIResult<SlaughterModel>> Handle(GetSlaughterCommand request, CancellationToken cancellationToken)
        {
            APIResult<SlaughterModel> result = new APIResult<SlaughterModel>();
            var res = salughterRepo.GetAll().FirstOrDefault(x => x.Batch == request.Batch);
            result.Message = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
